import 'package:flutter/material.dart';
import 'package:flutter_changdian_football/pages/clubs/club_news/club_news_controller.dart';
import 'package:flutter_changdian_football/utils/str_utils.dart';
import 'package:flutter_changdian_football/widget/screenutil/custom_screenutil.dart';
import 'package:get/get.dart';

class ClubMessageDialog {

  static void show(
    BuildContext mContext, {
      Function? confirmTap,
      int index = 0,
      Function? rejectTap,
      Function? passTap
    }
  ) {
    showDialog(
      barrierDismissible: false,
      context: mContext,
      builder: (BuildContext context) {
        return WillPopScope(
          onWillPop: () async => false,
          child: ShowDialogPage(
            confirmTap: confirmTap,
            index: index,
            rejectTap: rejectTap,
            passTap: passTap
          ),
        );
      }
    );
  }

}



class ShowDialogPage extends Dialog {
  ShowDialogPage({
    this.confirmTap,
    this.cancelTap,
    this.index = 0,
    this.rejectTap,
    this.passTap
  });

  // 确认
  final Function? confirmTap;
  final Function? cancelTap;
  final int index;

  final Function? rejectTap;
  final Function? passTap;

  @override
  Widget build(BuildContext dContext) {
    return Material(
      //创建透明层
      type: MaterialType.transparency, //透明类型
      //自定义dialog布局
      child: GetBuilder<ClubNewsController>(
        builder: (clubNewsController) {
          return Center(
            child: RichText(
              text: TextSpan(
                children: [
                  WidgetSpan(
                    child: Column(
                      mainAxisSize: MainAxisSize.min,
                      children: [
                        Stack(
                          clipBehavior: Clip.none,
                          alignment: Alignment.center,
                          children: [
                            Container(
                              margin: EdgeInsets.symmetric(horizontal: 40.w),
                              width: double.infinity,
                              decoration: BoxDecoration(
                                color: Colors.white,
                                borderRadius: BorderRadius.circular(12.r)
                              ),
                              child: Column(
                                crossAxisAlignment: CrossAxisAlignment.start,
                                mainAxisSize: MainAxisSize.min,
                                children: [
                                  SizedBox(height: 46.w,),

                                  Container(
                                    alignment: Alignment.center,
                                    child: Row(
                                      mainAxisAlignment: MainAxisAlignment.center,
                                      children: [
                                        Text(clubNewsController.checkMessageList[index].nickname ?? '', style: TextStyle(fontSize: 18.sp, color: const Color(0xff323232)),),
                                        SizedBox(width: 6.w,),
                                        SizedBox(
                                          width: 14.w,
                                          height: 14.w,
                                          child: Image.asset(StrUtils.getSexImage(clubNewsController.checkMessageList[index].sex ?? 0)),
                                        )
                                      ],
                                    ),
                                  ),

                                  SizedBox(height: 20.w,),


                                  Container(
                                    constraints: BoxConstraints(
                                      maxHeight: 240.w
                                    ),
                                    child: ListView.separated(
                                      itemCount: 1,
                                      padding: EdgeInsets.only(left: 12.w, right: 29.w),
                                      shrinkWrap: true,
                                      physics: const BouncingScrollPhysics(),
                                      separatorBuilder: (context, subIndex) {
                                        return SizedBox(height: 16.w,);
                                      },
                                      itemBuilder: (BuildContext context, int subIndex) {
                                        return Container(
                                          padding: EdgeInsets.symmetric(vertical: 7.w, horizontal: 12.w),
                                          decoration: BoxDecoration(
                                            color: const Color(0xffF8FAF9),
                                            borderRadius: BorderRadius.only(
                                              topRight: Radius.circular(15.r),
                                              bottomLeft: Radius.circular(15.r),
                                              bottomRight: Radius.circular(15.r)
                                            )
                                          ),
                                          child: Text(clubNewsController.checkMessageList[subIndex].message ?? '', style: TextStyle(color: const Color(0xff242941), fontSize: 12.sp, height: 1.5),),
                                        );
                                      },
                                    ),
                                  ),


                                  if (clubNewsController.checkMessageList[index].status == 'WAIT_DEAL') ...[
                                    Container(
                                      padding: EdgeInsets.only(left: 12.w, right: 12.w, bottom: 10.w, top: 30.w),
                                      child: Row(
                                        children: [
                                          Expanded(
                                            child: GestureDetector(
                                              behavior: HitTestBehavior.translucent,
                                              onTap: () {
                                                rejectTap?.call();
                                              },
                                              child: Container(
                                                padding: EdgeInsets.symmetric(vertical: 12.w),
                                                decoration: BoxDecoration(
                                                  borderRadius: BorderRadius.circular(8.r),
                                                  border: Border.all(
                                                    width: 1.w,
                                                    color: const Color(0xff999999)
                                                  )
                                                ),
                                                alignment: Alignment.center,
                                                child: Text('拒绝', style: TextStyle(fontSize: 14.sp, color: const Color(0xff999999), fontWeight: FontWeight.w500),),
                                              ),
                                            ),
                                          ),
                                          SizedBox(width: 18.w,),
                                          Expanded(
                                            child: GestureDetector(
                                              behavior: HitTestBehavior.translucent,
                                              onTap: () {
                                                passTap?.call();
                                              },
                                              child: Container(
                                                padding: EdgeInsets.symmetric(vertical: 12.w),
                                                decoration: BoxDecoration(
                                                  color: const Color(0xff499360),
                                                  borderRadius: BorderRadius.circular(8.r),
                                                  border: Border.all(
                                                    width: 1.w,
                                                    color: const Color(0xff499360)
                                                  )
                                                ),
                                                alignment: Alignment.center,
                                                child: Text('通过', style: TextStyle(fontSize: 14.sp, color: Colors.white, fontWeight: FontWeight.w500),),
                                              ),
                                            ),
                                          )
                                        ],
                                      ),
                                    ),
                                  ] else ...[
                                    Container(
                                      padding: EdgeInsets.only(left: 12.w, right: 12.w, bottom: 10.w, top: 30.w),
                                      child: GestureDetector(
                                        behavior: HitTestBehavior.translucent,
                                        onTap: () {
                                          confirmTap?.call();
                                        },
                                        child: Container(
                                          padding: EdgeInsets.symmetric(vertical: 12.w),
                                          decoration: BoxDecoration(
                                            color: const Color(0xff499360),
                                            borderRadius: BorderRadius.circular(8.r),
                                            border: Border.all(
                                              width: 1.w,
                                              color: const Color(0xff499360)
                                            )
                                          ),
                                          alignment: Alignment.center,
                                          child: Text('确认', style: TextStyle(fontSize: 14.sp, color: Colors.white, fontWeight: FontWeight.w500),),
                                        ),
                                      ),
                                    )
                                  ]
                                ],
                              ),
                            ),

                            Positioned(
                              top: -34.w,
                              child: Container(
                                width: 68.w,
                                height: 68.w,
                                decoration: BoxDecoration(
                                  color: Colors.white,
                                  borderRadius: BorderRadius.circular(68.r)
                                ),
                                padding: EdgeInsets.all(2.w),
                                child: ClipRRect(
                                  borderRadius: BorderRadius.circular(68.r),
                                  child: Image.network(clubNewsController.checkMessageList[index].userImg ?? '', fit: BoxFit.fill,),
                                ),
                              )
                            )
                          ],
                        ),

                        SizedBox(height: 60.w,),

                        GestureDetector(
                          behavior: HitTestBehavior.translucent,
                          onTap: () {
                            Get.back();
                          },
                          child: Container(
                            width: 35.w,
                            height: 35.w,
                            decoration: BoxDecoration(
                              border: Border.all(
                                width: 1.5.w,
                                color: const Color(0xffFFFFFF)
                              ),
                              borderRadius: BorderRadius.circular(35.r)
                            ),
                            child: const Icon(Icons.close, color: Colors.white,),
                          ),
                        )
                      ],
                    )
                  ),
                ]
              ),
            ),
          );
        }
      )
    );
  }
}





